package com.bjpowernode.servlets;

import java.io.IOException;
import java.util.Enumeration;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class SomeServlet implements Servlet {
	private ServletConfig config;
	@Override
	public void init(ServletConfig config) throws ServletException {
		this.config = config;
		System.out.println("config = " + config);
	}

	@Override
	public ServletConfig getServletConfig() {
		return config;
	}

	@Override
	public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
		// 获取Servlet的名称
		String servletName = config.getServletName();
		System.out.println("servletName = " + servletName);
		
		// 获取ServletContext对象
		ServletContext servletContext = config.getServletContext();
		System.out.println("servletContext = " + servletContext);
		
		// 获取所有的初始化参数
		Enumeration<String> names = config.getInitParameterNames();
		// 遍历枚举
		while(names.hasMoreElements()) {
			// 获取枚举的当前遍历的值
			String name = names.nextElement();
			// 获取指定参数的值
			String value = config.getInitParameter(name);
			System.out.println(name + " = " + value);
		}
	}

	@Override
	public String getServletInfo() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		
	}

}
